# 文件路径需要使用/
file = r"D:\workspace\pythonTest\src\test2.txt"

fo = open(file, "r", encoding="utf-8")
print("文件名是:", fo.name)
list1 = []
# 读取文件
for index in fo:
    print(index)
    list1.append(index)

print(list1)
print("是否已关闭:", fo.closed)
fo.close()  # 关闭文件
print("是否已关闭:", fo.closed)

